package com.hackordie.operations.creates;

import org.junit.Assert;
import org.junit.BeforeClass;

import com.hackordie.commons.HackOrDieResult;
import com.hackordie.commons.constants.ConsFirewall;
import com.hackordie.commons.constants.ConsHardDisk;
import com.hackordie.commons.constants.ConsNetworkCard;
import com.hackordie.commons.constants.ConsPowerSupply;
import com.hackordie.commons.constants.ConsProcessor;
import com.hackordie.commons.constants.ConsRamMemory;
import com.hackordie.commons.hardware.components.Firewall;
import com.hackordie.commons.hardware.components.HardDisk;
import com.hackordie.commons.hardware.components.NetworkCard;
import com.hackordie.commons.hardware.components.PowerSupply;
import com.hackordie.commons.hardware.components.Processor;
import com.hackordie.commons.hardware.components.RamMemory;
import com.hackordie.exceptions.HackOrDieException;
import com.hackordie.operations.deletes.DeleteComponent;

//********************************************************************//
//** INICIALIZACION DE LA BASE DE DATOS CON COMPONENTES PARA TESTEO **//
//********************************************************************//


public class CreateComponents {

    private static Firewall firewall1;
    private static HardDisk hardDisk1;
    private static NetworkCard networkCard1;
    private static PowerSupply powerSupply1;
    private static Processor processor1;
    private static RamMemory ramMemory1; 
    
    private static Firewall firewall2;
    private static HardDisk hardDisk2;
    private static NetworkCard networkCard2;
    private static PowerSupply powerSupply2;
    private static Processor processor2;
    private static RamMemory ramMemory2; 
           
    private static HackOrDieResult result;
    private static CreateComponent createComponent;
    
    @BeforeClass
    public static void initialize() {     
                      
        result = new HackOrDieResult();
        
        firewall1    = new Firewall(ConsFirewall.firewallName1, 
                                   ConsFirewall.energyTurnOn1, 
                                   ConsFirewall.difficultAccess1, 
                                   ConsFirewall.prize1);
        
        powerSupply1  = new PowerSupply(ConsPowerSupply.powerSypplyName1, 
                                       ConsPowerSupply.generatedEnergy1, 
                                       ConsPowerSupply.prize1);
        
        hardDisk1     = new HardDisk(ConsHardDisk.hardDiskName1, 
                                    ConsHardDisk.energyTurnOn1, 
                                    ConsHardDisk.capacity1, 
                                    ConsHardDisk.prize1);
                                    
        networkCard1 = new NetworkCard(ConsNetworkCard.networkCardName1, 
                                      ConsNetworkCard.energyTurnOn1, 
                                      ConsNetworkCard.ipDirection1, 
                                      ConsNetworkCard.speed1, 
                                      ConsNetworkCard.prize1);
        
        processor1   = new Processor(ConsProcessor.processorName1, 
                                    ConsProcessor.energyTurnOn1, 
                                    ConsProcessor.speedForCores1, 
                                    ConsProcessor.cores1, 
                                    100,                       //level en skill, no se almacena 
                                    ConsProcessor.prize1);
        
        ramMemory1 = new RamMemory(ConsRamMemory.ramMemoryname1, 
                                   ConsRamMemory.energyTurnOn1, 
                                   ConsRamMemory.totalCapacity1,
                                   ConsRamMemory.prize1);
        
        firewall2    = new Firewall(ConsFirewall.firewallName2, 
                                    ConsFirewall.energyTurnOn2, 
                                    ConsFirewall.difficultAccess2, 
                                    ConsFirewall.prize2);

        powerSupply2  = new PowerSupply(ConsPowerSupply.powerSypplyName2, 
                                        ConsPowerSupply.generatedEnergy2, 
                                        ConsPowerSupply.prize2);

        hardDisk2     = new HardDisk(ConsHardDisk.hardDiskName2, 
                                     ConsHardDisk.energyTurnOn2, 
                                     ConsHardDisk.capacity2, 
                                     ConsHardDisk.prize2);
                         
        networkCard2  = new NetworkCard(ConsNetworkCard.networkCardName2, 
                                        ConsNetworkCard.energyTurnOn2, 
                                        ConsNetworkCard.ipDirection2, 
                                        ConsNetworkCard.speed2, 
                                        ConsNetworkCard.prize2);
        
        processor2   = new Processor(ConsProcessor.processorName2, 
                                     ConsProcessor.energyTurnOn2, 
                                     ConsProcessor.speedForCores2, 
                                     ConsProcessor.cores1, 
                                     100,                       //level en skill, no se almacena 
                                     ConsProcessor.prize2);
        
        ramMemory2   = new RamMemory(ConsRamMemory.ramMemoryname2, 
                                     ConsRamMemory.energyTurnOn2, 
                                     ConsRamMemory.totalCapacity2,
                                     ConsRamMemory.prize2);
    }
    
 //   @Test
    public void insertOnBD() throws HackOrDieException {
        
        createComponent = new CreateComponent(firewall1);        
        result = createComponent.execute();
        Assert.assertTrue(result.isCorrect());    
        
        createComponent = new CreateComponent(firewall2);        
        result = createComponent.execute();
        Assert.assertTrue(result.isCorrect()); 
        
        createComponent = new CreateComponent(hardDisk1);        
        result = createComponent.execute();
        Assert.assertTrue(result.isCorrect()); 
        
        createComponent = new CreateComponent(hardDisk2);        
        result = createComponent.execute();
        Assert.assertTrue(result.isCorrect());         
        
        createComponent = new CreateComponent(powerSupply1);        
        result = createComponent.execute();
        Assert.assertTrue(result.isCorrect()); 
        
        createComponent = new CreateComponent(powerSupply2);        
        result = createComponent.execute();
        Assert.assertTrue(result.isCorrect()); 
        
        createComponent = new CreateComponent(networkCard1);        
        result = createComponent.execute();
        Assert.assertTrue(result.isCorrect()); 
        
        createComponent = new CreateComponent(networkCard2);        
        result = createComponent.execute();
        Assert.assertTrue(result.isCorrect()); 
        
        createComponent = new CreateComponent(processor1);        
        result = createComponent.execute();
        Assert.assertTrue(result.isCorrect()); 
        
        createComponent = new CreateComponent(processor2);        
        result = createComponent.execute();
        Assert.assertTrue(result.isCorrect()); 
        
        createComponent = new CreateComponent(ramMemory1);        
        result = createComponent.execute();
        Assert.assertTrue(result.isCorrect()); 
        
        createComponent = new CreateComponent(ramMemory2);        
        result = createComponent.execute();
        Assert.assertTrue(result.isCorrect()); 
    }
    
  //************************************************************************//
  //** DESCOMENTAR Y EJECUTAR ANTES DE REALIZAR TESTS PARA LIMPIAR LA BD **//
  //************************************************************************//
    
//    @Test
    public void deleteAll() throws HackOrDieException {
         new DeleteComponent(ramMemory1.getComponentName()).execute();
         new DeleteComponent(hardDisk1.getComponentName()).execute();
         new DeleteComponent(processor1.getComponentName()).execute();
         new DeleteComponent(networkCard1.getComponentName()).execute();
         new DeleteComponent(powerSupply1.getComponentName()).execute();
         new DeleteComponent(firewall1.getComponentName()).execute();
         
         new DeleteComponent(ramMemory2.getComponentName()).execute();
         new DeleteComponent(hardDisk2.getComponentName()).execute();
         new DeleteComponent(processor2.getComponentName()).execute();
         new DeleteComponent(networkCard2.getComponentName()).execute();
         new DeleteComponent(powerSupply2.getComponentName()).execute();
         new DeleteComponent(firewall2.getComponentName()).execute();
    }
}
